package com.ruoyi.work.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.page.Pages;
import com.ruoyi.common.core.page.Query;
import com.ruoyi.common.query.QueryTool;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.work.mapper.WorkOrderDetailMapper;
import com.ruoyi.work.domain.WorkOrderDetail;
import com.ruoyi.work.service.IWorkOrderDetailService;

/**
 * 工单明细Service业务层处理
 *
 * @author xwj
 * @date 2024-08-13
 */
@Service
public class WorkOrderDetailServiceImpl extends ServiceImpl<WorkOrderDetailMapper, WorkOrderDetail> implements IWorkOrderDetailService {
    @Autowired
    private WorkOrderDetailMapper workOrderDetailMapper;

    /**
     * 查询工单明细
     *
     * @param id 工单明细主键
     * @return 工单明细
     */
    @Override
    public WorkOrderDetail selectWorkOrderDetailById(Long id) {
        return workOrderDetailMapper.selectWorkOrderDetailById(id);
    }

    /**
     * 查询工单明细列表
     *
     * @param workOrderDetail 工单明细
     * @return 工单明细
     */
    @Override
    public List<WorkOrderDetail> selectWorkOrderDetailList(WorkOrderDetail workOrderDetail) {
        return workOrderDetailMapper.selectWorkOrderDetailList(workOrderDetail);
    }

    /**
     * 新增工单明细
     *
     * @param workOrderDetail 工单明细
     * @return 结果
     */
    @Override
    public WorkOrderDetail insertWorkOrderDetail(WorkOrderDetail workOrderDetail) {

        //  workOrderDetailMapper.insertWorkOrderDetail(workOrderDetail);
        save(workOrderDetail);
        return workOrderDetail;
    }

    /**
     * 修改工单明细
     *
     * @param workOrderDetail 工单明细
     * @return 结果
     */
    @Override
    public WorkOrderDetail updateWorkOrderDetail(WorkOrderDetail workOrderDetail) {

        //  workOrderDetailMapper.updateWorkOrderDetail(workOrderDetail);
        updateById(workOrderDetail);
        return workOrderDetail;
    }

    /**
     * 批量删除工单明细
     *
     * @param ids 需要删除的工单明细主键
     * @return 结果
     */
    @Override
    public int deleteWorkOrderDetailByIds(Long[] ids) {
        return workOrderDetailMapper.deleteWorkOrderDetailByIds(ids);
    }

    /**
     * 条件删除
     * @param workOrderDetail 工单明细
     * @return
     */
    @Override
    public int delete(WorkOrderDetail workOrderDetail) {
        QueryWrapper<WorkOrderDetail> qw = new QueryWrapper<>();
        QueryTool.condition(qw, workOrderDetail);
        return baseMapper.delete(qw);
    }

    /**
     * mp分页
     * @param workOrderDetail 工单明细
     * @return
     */
    @Override
    public Pages<WorkOrderDetail> queryPage(WorkOrderDetail workOrderDetail) {
        QueryWrapper<WorkOrderDetail> qw = new QueryWrapper<>();
        QueryTool.condition(qw, workOrderDetail);
        IPage<WorkOrderDetail> ipage = new Query<WorkOrderDetail>().getPage(workOrderDetail);

        IPage<WorkOrderDetail> page = this.page(
                ipage,
                qw
        );
        return new Pages<>(page);
    }

    /**
     * 删除工单明细信息
     *
     * @param id 工单明细主键
     * @return 结果
     */
    @Override
    public int deleteWorkOrderDetailById(Long id) {
        return workOrderDetailMapper.deleteWorkOrderDetailById(id);
    }
}
